package com.hnas.account.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.hnas.account.dao.AccountDAO;
import com.hnas.account.orm.Account;
import com.hnas.account.service.dto.DTOAccount;
import com.hnas.account.service.dto.search.DTOAccountSearch;
import com.hnas.core.dto.DTOPagedList;

@Component("accountService")
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public class AccountServiceImpl implements AccountService{

	@Autowired
	private AccountDAO accountDAO;
	
	@Override
	public Account saveOrUpdate(DTOAccount dto) throws Exception {
		return this.accountDAO.saveOrUpdate(dto);
	}

	@Override
	public DTOPagedList<DTOAccount> search(DTOAccountSearch criteria) {
		return this.accountDAO.search(criteria);
	}

	@Override
	public Boolean register(DTOAccount dto) {
		Account account = null;
		try{
			account = this.accountDAO.saveOrUpdate(dto);
		}catch(Exception e){
			e.printStackTrace();
		}
		return account!=null;
	}
	
	@Override
	public Account findById(String id) {
		return accountDAO.find(id);
	}

	@Override
	public List<Account> findAll() {
		return this.accountDAO.findAll();
	}

	@Override
	public DTOAccount setCardInfo(DTOAccount dto) {
		return accountDAO.setCardInfo(dto);
	}

}
